﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Hydra.Core
{
    internal class Surgeon : IDoctor
    {
        // WCF server
        private readonly Stethoscope _stethoscope;
        // Injector
        private readonly IScalpel _scalpel;

        public Surgeon()
        {
            // set environment variable to tell we are the host
            Environment.SetEnvironmentVariable("HydraHost", "$");

            _stethoscope = new Stethoscope();
            _scalpel = Environment.Is64BitProcess ? (IScalpel) new X64Scalpel() : new X86Scalpel();
        }

        public void Inject(int pid)
        {
            _stethoscope.Start(pid);
            _scalpel.Inject(pid);
        }

        public void Uninject()
        {
            _stethoscope.Stop();
        }

        public void ApplyDetours(byte[] assembly)
        {
            _stethoscope.ApplyDetours(assembly);
        }

        public void ReleaseDetours()
        {
            _stethoscope.ReleaseDetours();
        }
    }
}